<template>
  <!-- <div class="absolute bottom-0 right-0 p-4 z-50">
    <el-button-group>
      <el-button type="primary" @click="setUserRole('admin')">管理员</el-button>
      <el-button @click="setUserRole('police')">普通警员</el-button>
    </el-button-group>
  </div> -->
  <el-table border :data="data" style="width: 100%" :height="height">
    <el-table-column prop="itemName" label="用户" />
    <el-table-column prop="sgCount" label="状态" />
    <el-table-column prop="sgCountRatio" label="占比" />
    <el-table-column prop="swrsCount" label="死亡案件数" />
    <el-table-column prop="swrsCountRatio" label="占比" />
    <el-table-column label="操作">
      <template #default="scope">
        <el-button type="text" size="small" @click="handleView(scope.row)"
          >查看</el-button
        >
        <el-button
          type="text"
          size="small"
          @click="handleModify(scope.row)"
          v-if="userRole === 'admin'"
          >修改</el-button
        >
      </template>
    </el-table-column>
  </el-table>

  <AuthorityManagements
    :page-list="pageList"
    :user-role="userRole"
    ref="AuthorityManagementS"
    @confirm="handleAuthorityConfirm"
  />
</template>

<script setup>
import AuthorityManagements from "@/components/AuthorityManagements/index.vue";
// import { jurisdiction } from "@/store/modules/rectangle-dialog";
const AuthorityManagementS = ref();
const checkedPages = ref([]);
const pageList = ref([])
// const allItems =[
//           {
//             value: "hir",
//             name: "历史调查记录",
//             disabled: false,
//           },
//           {
//             value: "death",
//             name: "亡人事故报告的预览与导出",
//             disabled: false,
//           },
//           {
//             value: "a1",
//             name: "一般程序交通事故四项指数统计",
//             disabled: false,
//           },
//           {
//             value: "c2",
//             name: "各辖区交通事故多发路段",
//             disabled: false,
//           },
//           {
//             value: "b2",
//             name: "一般程序交通事故起数柱状图（月份）",
//             disabled: false,
//           },
//           {
//             value: "d1",
//             name: "一般程序事故认定原因统计表",
//             disabled: false,
//           },
//           {
//             value: "e1",
//             name: "事故形态统计",
//             disabled: false,
//           },
//           {
//             value: "e3",
//             name: "隔离设施情况",
//             disabled: false,
//           },
//           {
//             value: "a2",
//             name: "乡镇街道交通事故发生情况统计",
//             disabled: false,
//           },
//           {
//             value: "e2",
//             name: "车辆行驶状态统计",
//             disabled: false,
//           },
//           {
//             value: "f1",
//             name: "车辆登记/检验情况统计",
//             disabled: false,
//           },
//           {
//             value: "f2",
//             name: "车辆使用性质（十二类安全生产事故车辆标红）",
//             disabled: false,
//           },
//           {
//             value: "g1",
//             name: "天气情况统计",
//             disabled: false,
//           },
//           {
//             value: "g2",
//             name: "路面状况统计",
//             disabled: false,
//           },
//           {
//             value: "g3",
//             name: "路表情况统计",
//             disabled: false,
//           },
//           {
//             value: "g4",
//             name: "照明情况统计",
//             disabled: false,
//           },
//           {
//             value: "h1",
//             name: "交通事故责任者交通方式",
//             disabled: false,
//           },
//           {
//             value: "h2",
//             name: "交通事故责任者驾龄",
//             disabled: false,
//           },
//           {
//             value: "h3",
//             name: "交通事故责任者年龄",
//             disabled: false,
//           },
//           {
//             value: "h4",
//             name: "交通方式伤亡人数统计",
//             disabled: false,
//           },
//           {
//             value: "h5",
//             name: "伤亡人员职业统计",
//             disabled: false,
//           },
//           {
//             value: "h6",
//             name: "伤亡人员年龄统计",
//             disabled: false,
//           },
//         ]

const props = defineProps({
  data: {
    type: Array,
    default: () => [
      {
        itemName: "管理员",
        sgCount: 15,
        sgCountRatio: "30%",
        swrsCount: 2,
        swrsCountRatio: "10%",
        ssrsCount: 13,
        ssrsCountRatio: "65%",
        pageList: [
          {
            value: "amg",
            name: "权限管理",
            disabled: false,
          },
          {
            value: "hir",
            name: "历史调查记录",
            disabled: false,
          },
          {
            value: "death",
            name: "亡人事故报告的预览与导出",
            disabled: false,
          },
          {
            value: "a1",
            name: "一般程序交通事故四项指数统计",
            disabled: false,
          },
          {
            value: "c2",
            name: "各辖区交通事故多发路段",
            disabled: false,
          },
          {
            value: "b2",
            name: "一般程序交通事故起数柱状图（月份）",
            disabled: false,
          },
          {
            value: "d1",
            name: "一般程序事故认定原因统计表",
            disabled: false,
          },
          {
            value: "e1",
            name: "事故形态统计",
            disabled: false,
          },
          {
            value: "e3",
            name: "隔离设施情况",
            disabled: false,
          },
          {
            value: "a2",
            name: "乡镇街道交通事故发生情况统计",
            disabled: false,
          },
          {
            value: "e2",
            name: "车辆行驶状态统计",
            disabled: false,
          },
          {
            value: "f1",
            name: "车辆登记/检验情况统计",
            disabled: false,
          },
          {
            value: "f2",
            name: "车辆使用性质（十二类安全生产事故车辆标红）",
            disabled: false,
          },
          {
            value: "g1",
            name: "天气情况统计",
            disabled: false,
          },
          {
            value: "g2",
            name: "路面状况统计",
            disabled: false,
          },
          {
            value: "g3",
            name: "路表情况统计",
            disabled: false,
          },
          {
            value: "g4",
            name: "照明情况统计",
            disabled: false,
          },
          {
            value: "h1",
            name: "交通事故责任者交通方式",
            disabled: false,
          },
          {
            value: "h2",
            name: "交通事故责任者驾龄",
            disabled: false,
          },
          {
            value: "h3",
            name: "交通事故责任者年龄",
            disabled: false,
          },
          {
            value: "h4",
            name: "交通方式伤亡人数统计",
            disabled: false,
          },
          {
            value: "h5",
            name: "伤亡人员职业统计",
            disabled: false,
          },
          {
            value: "h6",
            name: "伤亡人员年龄统计",
            disabled: false,
          },
        ]
      },
      {
        itemName: "科技所",
        sgCount: 20,
        sgCountRatio: "40%",
        swrsCount: 3,
        swrsCountRatio: "15%",
        ssrsCount: 17,
        ssrsCountRatio: "85%",
        pageList: [
          {
            value: "hir",
            name: "历史调查记录",
            disabled: false,
          },
          {
            value: "death",
            name: "亡人事故报告的预览与导出",
            disabled: false,
          },
          {
            value: "a1",
            name: "一般程序交通事故四项指数统计",
            disabled: false,
          },
          {
            value: "c2",
            name: "各辖区交通事故多发路段",
            disabled: false,
          },
          {
            value: "b2",
            name: "一般程序交通事故起数柱状图（月份）",
            disabled: false,
          },
          {
            value: "d1",
            name: "一般程序事故认定原因统计表",
            disabled: false,
          },
          {
            value: "e1",
            name: "事故形态统计",
            disabled: false,
          },
          {
            value: "e3",
            name: "隔离设施情况",
            disabled: false,
          },
          {
            value: "a2",
            name: "乡镇街道交通事故发生情况统计",
            disabled: false,
          },
          {
            value: "e2",
            name: "车辆行驶状态统计",
            disabled: false,
          },
          {
            value: "f1",
            name: "车辆登记/检验情况统计",
            disabled: false,
          },
          {
            value: "f2",
            name: "车辆使用性质（十二类安全生产事故车辆标红）",
            disabled: false,
          },
          {
            value: "g1",
            name: "天气情况统计",
            disabled: false,
          },
          {
            value: "g2",
            name: "路面状况统计",
            disabled: false,
          },
          {
            value: "g3",
            name: "路表情况统计",
            disabled: false,
          },
          {
            value: "g4",
            name: "照明情况统计",
            disabled: false,
          },
          {
            value: "h1",
            name: "交通事故责任者交通方式",
            disabled: false,
          },
          {
            value: "h2",
            name: "交通事故责任者驾龄",
            disabled: false,
          },
          {
            value: "h3",
            name: "交通事故责任者年龄",
            disabled: false,
          },
          {
            value: "h4",
            name: "交通方式伤亡人数统计",
            disabled: false,
          },
          {
            value: "h5",
            name: "伤亡人员职业统计",
            disabled: false,
          },
          {
            value: "h6",
            name: "伤亡人员年龄统计",
            disabled: false,
          },
        ]
      },
      {
        itemName: "秩序大队",
        sgCount: 20,
        sgCountRatio: "40%",
        swrsCount: 3,
        swrsCountRatio: "15%",
        ssrsCount: 17,
        ssrsCountRatio: "85%",
        pageList: [
          {
            value: "death",
            name: "亡人事故报告的预览与导出",
            disabled: false,
          },
          {
            value: "a1",
            name: "一般程序交通事故四项指数统计",
            disabled: false,
          },
          {
            value: "c2",
            name: "各辖区交通事故多发路段",
            disabled: false,
          },
          {
            value: "b2",
            name: "一般程序交通事故起数柱状图（月份）",
            disabled: false,
          },
          {
            value: "d1",
            name: "一般程序事故认定原因统计表",
            disabled: false,
          },
          {
            value: "e1",
            name: "事故形态统计",
            disabled: false,
          },
          {
            value: "e3",
            name: "隔离设施情况",
            disabled: false,
          },
          {
            value: "a2",
            name: "乡镇街道交通事故发生情况统计",
            disabled: false,
          },
          {
            value: "e2",
            name: "车辆行驶状态统计",
            disabled: false,
          },
          {
            value: "f1",
            name: "车辆登记/检验情况统计",
            disabled: false,
          },
          {
            value: "f2",
            name: "车辆使用性质（十二类安全生产事故车辆标红）",
            disabled: false,
          },
          {
            value: "g1",
            name: "天气情况统计",
            disabled: false,
          },
          {
            value: "g2",
            name: "路面状况统计",
            disabled: false,
          },
          {
            value: "g3",
            name: "路表情况统计",
            disabled: false,
          },
          {
            value: "g4",
            name: "照明情况统计",
            disabled: false,
          },
          {
            value: "h1",
            name: "交通事故责任者交通方式",
            disabled: false,
          },
          {
            value: "h2",
            name: "交通事故责任者驾龄",
            disabled: false,
          },
          {
            value: "h3",
            name: "交通事故责任者年龄",
            disabled: false,
          },
          {
            value: "h4",
            name: "交通方式伤亡人数统计",
            disabled: false,
          },
          {
            value: "h5",
            name: "伤亡人员职业统计",
            disabled: false,
          },
          {
            value: "h6",
            name: "伤亡人员年龄统计",
            disabled: false,
          },
        ]
      },
      {
        itemName: "执勤民警",
        sgCount: 20,
        sgCountRatio: "40%",
        swrsCount: 3,
        swrsCountRatio: "15%",
        ssrsCount: 17,
        ssrsCountRatio: "85%",
        pageList: [
          {
            value: "a1",
            name: "一般程序交通事故四项指数统计",
            disabled: false,
          },
          {
            value: "c2",
            name: "各辖区交通事故多发路段",
            disabled: false,
          },
          {
            value: "b2",
            name: "一般程序交通事故起数柱状图（月份）",
            disabled: false,
          },
          {
            value: "d1",
            name: "一般程序事故认定原因统计表",
            disabled: false,
          },
          {
            value: "e1",
            name: "事故形态统计",
            disabled: false,
          },
          {
            value: "e3",
            name: "隔离设施情况",
            disabled: false,
          },
          {
            value: "a2",
            name: "乡镇街道交通事故发生情况统计",
            disabled: false,
          },
          {
            value: "e2",
            name: "车辆行驶状态统计",
            disabled: false,
          },
          {
            value: "f1",
            name: "车辆登记/检验情况统计",
            disabled: false,
          },
          {
            value: "f2",
            name: "车辆使用性质（十二类安全生产事故车辆标红）",
            disabled: false,
          },
          {
            value: "g1",
            name: "天气情况统计",
            disabled: false,
          },
          {
            value: "g2",
            name: "路面状况统计",
            disabled: false,
          },
          {
            value: "g3",
            name: "路表情况统计",
            disabled: false,
          },
          {
            value: "g4",
            name: "照明情况统计",
            disabled: false,
          },
          {
            value: "h1",
            name: "交通事故责任者交通方式",
            disabled: false,
          },
          {
            value: "h2",
            name: "交通事故责任者驾龄",
            disabled: false,
          },
          {
            value: "h3",
            name: "交通事故责任者年龄",
            disabled: false,
          },
          {
            value: "h4",
            name: "交通方式伤亡人数统计",
            disabled: false,
          },
          {
            value: "h5",
            name: "伤亡人员职业统计",
            disabled: false,
          },
          {
            value: "h6",
            name: "伤亡人员年龄统计",
            disabled: false,
          },
        ]
      },
    ],
  },
  height: {
    type: Number,
    default: 500,
  },
  userRole: {
    type: String,
    default: "police",
  },
  pageLists: {
    type: Array,
    default: () => [],
  },
});





// 已移除未使用的pageLists响应式变量

const userRole = ref(props.userRole);

const setUserRole = (role) => {
  userRole.value = role;
};

const selectedRow = ref(null);
const showAuthorityDialog = ref(false);
const actionType = ref(""); // 'view'或'modify'

const handleRowClick = (row) => {
  selectedRow.value = row;
};

const handleCheckedPagesUpdate = (newChecked) => {
  checkedPages.value = newChecked;
};

const handleAuthorityConfirm = (selectedPages) => {
  checkedPages.value = selectedPages;
  // 更新当前行的页面权限配置
  if (selectedRow.value) {
    selectedRow.value.pageList.forEach((p) => {
      p.disabled = !selectedPages.includes(p.path);
    });
  }
};

const handleView = (row) => {
  pageList.value = row.pageList;
  selectedRow.value = row;

  actionType.value = "view";
  userRole.value = "police";
  AuthorityManagementS.value.showAuthorityDialog = true;
};
const handleModify = (row) => {
  pageList.value = row.pageList;
  selectedRow.value = row;
  if (userRole.value === "admin") {
    actionType.value = "modify";
    AuthorityManagementS.value.showAuthorityDialog = true;
  }
};
</script>

  <style lang="less" scoped></style>
